﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using LHS.Core.TableInfo;
using MS.Core.Constants.Objects;

namespace LHS.Win
{
    public partial class frmSearchID : Form
    {
        LHS.Core.Clinical.ClinicalController objController = new LHS.Core.Clinical.ClinicalController();
        // Methods
        public frmSearchID()
        {
            this.InitializeComponent();
        }

        private void btnLapBenhAnMoi_CheckedChanged(object sender, EventArgs e)
        {
            searchID();
        }

        private void btnTaiKham_CheckedChanged(object sender, EventArgs e)
        {
            searchID();
        }

        private void searchID()
        {
            if (string.IsNullOrEmpty(txtPatID.Text))
            {
                MessageBox.Show("Vui lòng nhập thông tin Mã Bệnh Nhân","Thông Báo", MessageBoxButtons.OK);
                return;
            }
            List<ExpressionObject> param = new List<ExpressionObject>();
            param.Add(new ExpressionObject(InfoPatients.PATID, int.Parse(this.txtPatID.Text.Remove(txtPatID.Text.Length - 1, 1))));
            DataTable dt = objController.GetData("vw_SearchClinicalRecord", param);
            string clrISN = string.Empty;
            string patISN = string.Empty;
            string NhanBiet = string.Empty;
            if (dt == null || dt.Rows.Count == 0)
            {
                NhanBiet = "0";
            }
            else if (dt.Rows[0][InfoClinicalRecord.CLREXAMINATIONTIMES].ToString() == "" || dt.Rows[0][InfoClinicalRecord.CLREXAMINATIONTIMES].ToString() == string.Empty)
            {
                NhanBiet = "0";
                clrISN = dt.Rows[0][InfoClinicalRecord.CLRISN].ToString();
                patISN = dt.Rows[0][InfoClinicalRecord.PATISN].ToString();
            }
            else
            {
                NhanBiet = "1";
                clrISN = dt.Rows[0][InfoClinicalRecord.CLRISN].ToString();
                patISN = dt.Rows[0][InfoClinicalRecord.PATISN].ToString();
            }
            if (UserInformation.usrRole == "1")
            {
                frmHoSoBenhAn an = new frmHoSoBenhAn(clrISN ,NhanBiet,patISN);
                an.ShowInTaskbar = false;
                an.ShowDialog(this);
            }
            else
            {
                frmYTaLapMoi moi = new frmYTaLapMoi(clrISN, NhanBiet, patISN);
                moi.ShowInTaskbar = false;
                moi.ShowDialog();
            }
        }

        private void btnThoat_CheckedChanged(object sender, EventArgs e)
        {
            base.Close();
        }

        private void frmSearchID_Load(object sender, EventArgs e)
        {
            txtPatID.Focus();
        }
    }
}